Spell check column layout DXL

With reference to the request: Script to spell check on a column 

I created a script to display the spelling errors in the column with layout dxl but the function stops working after a few objects were edited (not fixed event count)

This failure may be related to Spell perms fail when Object Text is selected

Please advise?

 

/*
+-----------------------------------------------------------------------------+
|                                                                             |
|  File Name  : obj_spelling.inc                                              |
|                                                                             |
|  Description: Spelling Layout DXL.                                             |
|                                                                             |
+-----------------------------------------------------------------------------+
*/

// prevent dxl timeout dialog
pragma runLim, 0
// includes 

//globals
Dictionary d                  // open client dictionary
open(d, clientDictionary) 

//Check single word and show corrections 
string getSpellingSuggestion(string checkStr){
    Buffer suggestion=null 
    result = spell(checkStr) 
    string suggestion_list = ""
    if (!null result) 
    { 
       for suggestion in alternatives do 
       { 
          suggestion_list = suggestion_list " " stringOf(suggestion) ";" 
       } 
    } 
    return suggestion_list
}


// read object, check spelling and display alternatives
string getSpellingError(Object o, string attrName){
    Buffer retBuff=create
    string strBase_ID = identifier(o)
    string outStr = ""
    int iStart = 0
    int iFinish = 0
    int iLength = 0
    int sentenceStart=0
    int sentenceEnd=0
    int ruleType=0
    bool spellingErrorsFirst=true
    bool deletionError=false
    bool correctionComplete=false
    bool skipSentence=false
    if (o != null){
        // get attribute info
        string sCol =  probeAttr_(o, attrName) 
        if (sCol != ""){
            iLength = length(sCol)
            // process attribute
            spell( retBuff, o,  attrName, 
                                iStart, iFinish, 
                                sentenceStart, sentenceEnd, 
                                ruleType, spellingErrorsFirst, deletionError) 

            int blen = length(retBuff)
            while (blen>0){
                string word = sCol[iStart:iFinish]
                if(ruleType!=0){
                    outStr = "Rule[" ruleType "]: '" word "'" 
                    string sSug = getSpellingSuggestion(word)
                    if(sSug != null) { outStr = "" outStr "-" sSug "" }
                    display outStr "\n"
                } // end if(ruleType!=0
                getNextError(retBuff,
                             iStart, iFinish, 
                             sentenceStart, sentenceEnd, 
                             correctionComplete, skipSentence,
                             ruleType, deletionError)
                blen = length(retBuff)
                outStr = ""             
            } // end while (blen>0)
        } // end if (sCol != "")
    } // end if (o != null)
    delete retBuff
    return outStr
}


// display spelling errors in layout dxl column
{
    // object heading / object text
    string sObjectHeading = probeAttr_(obj, (NLS_("Object Heading")))
    string sObjectText = probeAttr_(obj, (NLS_("Object Text")))
    if (sObjectHeading != null){
        sObjectHeading = getSpellingError(obj,"Object Heading")
    }
    if (sObjectText != null){
        sObjectText = getSpellingError(obj,"Object Text")
    }
}


 

 


Yoda101 - Sat Mar 25 13:57:41 EDT 2017

Re: Spell check column layout DXL
Mathias Mamsch - Mon Mar 27 04:23:46 EDT 2017

Hmm - not seeing something bad - except that you never closing the dictionary. Did you try   close(Dictionary&, bool bSave) ? Regards, Mathias

Re: Spell check column layout DXL
Yoda101 - Mon Mar 27 04:32:34 EDT 2017

Mathias Mamsch - Mon Mar 27 04:23:46 EDT 2017

Hmm - not seeing something bad - except that you never closing the dictionary. Did you try   close(Dictionary&, bool bSave) ? Regards, Mathias

Mathias, thank you for the response - you are right of course and my colleague saw that immediately when he opeded the code!

Below the updated code:

/*
+-----------------------------------------------------------------------------+
|                                                                             |
|  File Name  : obj_spelling.inc                                              |
|                                                                             |
|  Description: Spelling Layout DXL.                                             |
|                                                                             |
+-----------------------------------------------------------------------------+
*/


// prevent dxl timeout dialog
pragma runLim, 0
// includes 

//globals

//Check single word and show corrections 
string getSpellingSuggestion(string checkStr){
    Buffer suggestion=null 
    result = spell(checkStr) 
    string suggestion_list = ""
    if (!null result) 
    { 
       for suggestion in alternatives do 
       { 
          suggestion_list = suggestion_list " " stringOf(suggestion) ";" 
       } 
    } 
    return suggestion_list
}


// read object, check spelling and display alternatives
string getSpellingError(Object o, string attrName){
    Buffer retBuff=create
    string strBase_ID = identifier(o)
    string outStr = ""
    int iStart = 0
    int iFinish = 0
    int iLength = 0
    int sentenceStart=0
    int sentenceEnd=0
    int ruleType=0
    bool spellingErrorsFirst=true
    bool deletionError=false
    bool correctionComplete=false
    bool skipSentence=false
    if (o != null){
        // get attribute info
        string sCol =  probeAttr_(o, attrName) 
        if (sCol != ""){
            iLength = length(sCol)
            // process attribute
            spell( retBuff, o,  attrName, 
                                iStart, iFinish, 
                                sentenceStart, sentenceEnd, 
                                ruleType, spellingErrorsFirst, deletionError) 

            int blen = length(retBuff)
            while (blen>0){
                string word = sCol[iStart:iFinish]
                if(ruleType!=0){
                    outStr = "Rule[" ruleType "]: '" word "'" 
                    string sSug = getSpellingSuggestion(word)
                    if(sSug != null) { outStr = "" outStr "-" sSug "" }
                    display outStr "\n"
                } // end if(ruleType!=0
                getNextError(retBuff,
                             iStart, iFinish, 
                             sentenceStart, sentenceEnd, 
                             correctionComplete, skipSentence,
                             ruleType, deletionError)
                blen = length(retBuff)
                outStr = ""             
            } // end while (blen>0)
        } // end if (sCol != "")
    } // end if (o != null)
    delete retBuff
    return outStr
}


// display spelling errors in layout dxl column
{
    Dictionary d                  // open client dictionary
    string err = open(d, clientDictionary) 

    if (null err) {        
        // object heading / object text
        string sObjectHeading = probeAttr_(obj, (NLS_("Object Heading")))
        string sObjectText = probeAttr_(obj, (NLS_("Object Text")))
        if (sObjectHeading != null){
            sObjectHeading = getSpellingError(obj,"Object Heading")
        }
        if (sObjectText != null){
            sObjectText = getSpellingError(obj,"Object Text")
        }
        close(d, false)
    }
}

Hope this is useful for other people as well - Jan Hurter


Attachments

layout_dxl_spelling.zip